import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/Layout'
import Login from '@/views/Login'
import Home from '@/views/Home'

// 产品管理
import GoodsManage from '@/views/GoodsManage'
import List from '@/views/GoodsManage/List'
import AddGoods from '@/views/GoodsManage/List/AddGoods'
import Category from '@/views/GoodsManage/Category'


//订单管理
import OrderManage from '@/views/OrderManage'
import OrderList from '@/views/OrderManage/List'
import Collect from '@/views/OrderManage/Collect'
import Contract from '@/views/OrderManage/Contract'


//广告管理
import Advert from '@/views/Advert'
import AdvertList from '@/views/Advert/List'


// 系统管理
const SystemManage = () =>import('@/views/SystemManage')
const Role = () =>import('@/views/SystemManage/Role')
const Department = () =>import('@/views/SystemManage/Department')


// 自己跳自己
// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location){
return originalPush.call(this , location).catch(err=>err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location){
return originalReplace.call(this , location).catch(err=>err)
}



Vue.use(VueRouter)
//component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
const routes = [
  {
    path: '/',
    name:'layout',
    component: Layout,
    meta:{
      title:'首页',
      isLogin:true,   // 是否需要登录
    },
    redirect:'/',
    children:[
        {
          path: '/',
          name:'home',
          component:Home,
          meta:{
            title:'首页',
          },
        },
        {
          path: '/goods',
          name:'goodsmanage',
          component: GoodsManage,
          redirect:'/goods/list',
          meta:{
             title:'产品管理',
          },
          children:[
            {
              path: 'list',
              name:'list',
              component: List,
              meta:{
                title:'产品列表',
              },
            },
            {
              path: 'category',
              name:'category',
              component: Category,
              meta:{
                title:'产品分类',
              },
            },
            {
              path: 'addgoods',   // 商品添加和编辑
              name:'addgoods',
              component: AddGoods,
              // 路由元信息
              meta:{
                activeMenu:'/goods/list',
                title:'商品详情',
              }
            },
          ]
        },
        {
          path: '/order',
          name:'ordermanage',
          component: OrderManage,
          redirect:'/order/list',
          meta:{
            title:'订单管理',
          },
          children:[
            {
              path: 'list',
              name:'list',
              component: OrderList,
              meta:{
                title:'订单列表',
              },
            },
            {
              path: 'collect',
              name:'collect',
              component: Collect,
              meta:{
                title:'订单汇总',
              },
            },
            {
              path: 'contract',
              name:'contract',
              component: Contract,
              meta:{
                title:'订单合同',
              },
            },
          ]
        },
        {
          path: '/advert',
          name:'advert',
          component: Advert,
          redirect:'/advert/list',
          meta:{
            title:'广告管理',
          },
          children:[
            {
              path: 'list',
              name:'list',
              component: AdvertList,
              meta:{
                title:'广告列表',
              },
            },
          ]
        },
        {
          path: '/system',
          name:'system',
          component: SystemManage,
          redirect:'/system/role',
          meta:{
            title:'系统管理',
          },
          children:[
            {
              path: 'role',
              name:'role',
              component: Role,
              meta:{
                title:'角色管理',
              },
            },
            {
              path: 'department',
              name:'department',
              component: Department,
              meta:{
                title:'部门管理',
              },
            },
          ]
        },
    ]
  },
  {
    path: '/login',
    name:'login',
    component: Login
  },
 
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


export default router
